package org.example.innovate.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.example.innovate.domain.PostView;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;

/**
* @author Administrator
* @description 针对表【post_view】的数据库操作Mapper
* @createDate 2025-03-13 17:01:49
* @Entity org.example.innovate.domain.PostView
*/
@Mapper
public interface PostViewMapper extends BaseMapper<PostView> {
    @Select("SELECT * FROM ("
            + "    SELECT *, ROW_NUMBER() OVER (PARTITION BY post_id ORDER BY viewed_at DESC) AS rn "
            + "    FROM post_view "
            + "    WHERE user_id = #{user_id} "
            + ") sub "
            + "WHERE rn = 1 "
            + "ORDER BY viewed_at DESC")
    List<PostView> selectLatestPostView(@Param("user_id") int user_id);
}




